function th5typeput()

fprintf('\tTesting H5TYPEPUT...  ' );
v = version('-release');
switch(v)
    case { '2006b','2007a', '2007b', '2008a', '2008b', '2009a'}
        fprintf('\n\t\tNot available on release %s.\n', v);
		return
end

tfile='testlink6.h5';
gentestfile(tfile);

test_type_put(tfile);
test_struct_put(tfile)
%delete(tfile);

fprintf('OK\n');
end

function gentestfile(fname)

h5id=h5filecreate(fname);
h5groupput(fname,'/testgroup');
%add a group
H5F.close(h5id);
end
%--------------------------------------------------------------------------
function test_type_put(fname)

tid=H5T.copy('H5T_NATIVE_DOUBLE');
h5typeput(fname,'/testgroup/type1',tid);
hi=hdf5info(fname);
if (~isequal(hi.GroupHierarchy.Groups(1).Datatypes(1).Class,'H5T_FLOAT'))
    error('new datatype does not match');
end
end

%--------------------------------------------------------------------------
function test_struct_put(fname)

a.a=1;
a.c=2;
a.d=5;
a.e.a=3;
a.e.b=6;
a.e.m=int32(4);
h5typeput(fname,'/testgroup/type2',a);

hi=hdf5info(fname);
if (~isequal(hi.GroupHierarchy.Groups(1).Datatypes(2).Class,'H5T_COMPOUND'))
    error('new datatype does not match');
end
flags = 'H5F_ACC_RDWR';
plist_id = 'H5P_DEFAULT';


fid = H5F.open ( fname, flags, plist_id );
tid=H5T.open(fid,'/testgroup/type2');
if (H5T.get_size(tid)~=44)
    error('incorrect type size');
end

if (H5T.get_nmembers(tid)~=4)
    error('incorrect number of members');
end

if (~isequal(H5T.get_member_name(tid,3),'e'))
    error('non-matching names');
end
tidm=H5T.get_member_type(tid,3);

if (H5T.get_nmembers(tidm)~=3)
    error('incorrect number of members');
end
H5T.close(tidm);
H5T.close(tid);
H5F.close(fid);

end
